/*
 * Copyright (c) 2023 huipei.x
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.xphsc.kubernetes.core.executor;

import io.kubernetes.client.PodLogs;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.apis.*;
import org.apache.commons.lang3.StringUtils;

/**
 * {@link }
 * @author <a href="xiongpeih@163.com">huipei.x</a>
 * @description: Kubernetes API交互
 * @since 1.0.0
 */
public class KubernetesApiExecutor<T> extends AbstractExecutor<T> {
    private String kubernetesApiMode;
    private  T entity;
    public KubernetesApiExecutor(ApiClient client,KubernetesApiMode kubernetesApiMode) {
        super(client);
        this.kubernetesApiMode=kubernetesApiMode.name();
    }

    @Override
    protected  T doExecute() {
        if (StringUtils.isNotBlank(kubernetesApiMode)) {
            switch (kubernetesApiMode){
                case "CORE":
                    entity = (T) new CoreV1Api(this.getClient());
                    break;
                case "APPS":
                    entity = (T) new AppsV1Api(this.getClient());
                    break;
                case "NETWORKING":
                    entity = (T) new NetworkingV1Api(this.getClient());
                    break;
                case "BATCH":
                    entity = (T) new BatchV1Api(this.getClient());
                    break;
                case "STORAGE":
                    entity = (T) new StorageV1Api(this.getClient());
                    break;
                case "LOGS":
                    entity = (T) new PodLogs(this.getClient());
                    break;
                case "VERSION":
                    entity = (T) new VersionApi(this.getClient());
                    break;
                case "SCHEDULING":
                    entity = (T) new SchedulingV1Api(this.getClient());
                    break;
                case "RBAC":
                    entity = (T) new RbacAuthorizationV1Api(this.getClient());
                    break;
                case "POLICY":
                    entity = (T) new PolicyV1Api(this.getClient());
                    break;
                case "OPENID":
                    entity = (T) new OpenidApi(this.getClient());
                    break;
                case "NODE":
                    entity = (T) new NodeV1Api(this.getClient());
                    break;
                case "INTERNAL":
                    entity = (T) new InternalApiserverV1alpha1Api(this.getClient());
                    break;
                case "FLOWCONTROL":
                    entity = (T) new FlowcontrolApiserverV1beta2Api(this.getClient());
                    break;
                case "EVENTS":
                    entity = (T) new EventsV1Api(this.getClient());
                    break;
                case "DISCOVERY":
                    entity = (T) new DiscoveryV1Api(this.getClient());
                    break;
                case "CUSTOMOBJECTS":
                    entity = (T) new CustomObjectsApi(this.getClient());
                    break;
                case "COORDINATION":
                    entity = (T) new CoordinationV1Api(this.getClient());
                    break;
                case "CERTIAFICATES":
                    entity = (T) new CertificatesV1Api(this.getClient());
                    break;
                case "AUTOSCALING":
                    entity = (T) new AutoscalingV2Api(this.getClient());
                    break;
                case "AUTHOROZATION":
                    entity = (T) new AuthorizationV1Api(this.getClient());
                    break;
                case "AUTHENTOCATION":
                    entity = (T) new AuthenticationV1Api(this.getClient());
                    break;
                case "APIREGISTRATION":
                    entity = (T) new ApiregistrationV1Api(this.getClient());
                    break;
                case "APIEXTENSIONS":
                    entity = (T) new ApiextensionsV1Api(this.getClient());
                    break;
                case "ADMISS":
                    entity = (T) new AdmissionregistrationV1Api(this.getClient());
                    break;
                default:

            }
        }
        return (T) entity;
    }
    public static enum KubernetesApiMode {
        /**
         *
         */
        CORE,
        APPS,
        NETWORKING,
        BATCH,
        STORAGE,
        LOGS,
        VERSION,
        SCHEDULING,
        RBAC,
        POLICY,
        OPENID,
        NODE,
        INTERNAL,
        FLOWCONTROL,
        EVENTS,
        DISCOVERY,
        CUSTOMOBJECTS,
        COORDINATION,
        CERTIAFICATES,
        AUTOSCALING,
        AUTHOROZATION,
        AUTHENTOCATION,
        APIREGISTRATION,
        APIEXTENSIONS,
        ADMISS,
        AUTO;

        private KubernetesApiMode() {

        }
        private KubernetesApiMode(String name) {
            this.name=name;
        }
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}


